package io.renren.modules.app.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.pms.entity.ProductAttributeEntity;
import io.renren.modules.pms.entity.dto.RelationAttrInfoByCidDTO;
import io.renren.modules.pms.service.ProductAttributeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 *
 *
 * @author LuoShun
 * @email lori6166@163.com
 * @date 2021-11-26 16:49:29
 */
@Api(tags  = "App商品类型属性")
@RestController
@RequestMapping("app/productAttribute")
public class AppProductAttributeController {
    @Autowired
    private ProductAttributeService productAttributeService;

    /**
     * 分页获取属性列表
     */
    @ApiOperation("分页获取属性列表")
    @GetMapping("/list/{cid}")
    public R list(
            @PathVariable long cid,
            @RequestParam Map<String, Object> params){
        PageUtils page = productAttributeService.queryPage(params,cid);


        return R.ok().put("page", page);
    }
    /**
     * 根据id获取商品属性
     */
    @ApiOperation("根据id获取商品类型")
    @GetMapping("/{id}")
    public R info(@PathVariable("id") Long id){
		ProductAttributeEntity productAttribute = productAttributeService.getById(id);

        return R.ok().put("data", productAttribute);
    }
    /**
     * 根据商品分类id获取筛选属性信息
     */
    @ApiOperation("根据商品分类id获取筛选属性信息")
    @GetMapping("/attrInfo/{cId}")
    public R getRelationAttrInfoByCid(@PathVariable("cId") Long productCategoryId){
        List<RelationAttrInfoByCidDTO> list = productAttributeService.getRelationAttrInfoByCid(productCategoryId);

        return R.ok().put("data", list);
    }

}
